//
//  YYHeaderView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/12.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "YuYueOrderDetailHeaderView.h"
#import "YuYueOrderDetailModel.h"

//左边间距15px
#define kYYHeaderViewMarginLeft (15)

@interface YuYueOrderDetailHeaderView()

/**div1*/
@property (nonatomic, strong) UIView *div0;
/**1.预约门店接口*/
@property (nonatomic, strong) UILabel *titleLb;

/**2.地址div*/
@property (nonatomic, strong) UIView *div1;
/**2-1地址icon*/
@property (nonatomic, strong) UIImageView *addressIv;
/**2-2shopName lb*/
@property (nonatomic, strong) UILabel *shopNameLb;
/**2-3address lb*/
@property (nonatomic, strong) UILabel *addressLb;


/**3.div2*/
@property (nonatomic, strong) UIView *div2;
/**3-1时间icon iv */
@property (nonatomic, strong) UIImageView *timeIv;
/**3-2用餐时间lb*/
@property (nonatomic, strong) UILabel *eatTimeLb;

@end

@implementation YuYueOrderDetailHeaderView

#pragma mark - 一 init
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
        self.backgroundColor = kMainLightGrayColor;
    }
    return self;
}

- (void)setupView {
    [self addSubview:self.div0];
    [self.div0 addSubview:self.titleLb];
    
    //==============================
    
    [self addSubview:self.div1];
    [self.div1 addSubview:self.addressIv];
    [self.div1 addSubview:self.shopNameLb];
    [self.div1 addSubview:self.addressLb];
    //==============================
    
    [self addSubview:self.div2];
    [self.div2 addSubview:self.timeIv];
    [self.div2 addSubview:self.eatTimeLb];
}


#pragma mark - 一 layout

- (void)layoutSubviews {
    [super layoutSubviews];
    //40
    [self.div0 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self);
        make.height.mas_equalTo(40);
    }];
    
    //60
    [self.div1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.div0.mas_bottom).offset(1); //线
        make.height.mas_equalTo(60);
    }];
    
    //40
    [self.div2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self);
        make.top.equalTo(self.div1.mas_bottom).offset(1);
        make.height.mas_equalTo(40);
    }];
    
    [self layoutDiv0];
    [self layoutDiv1];
    [self layoutDiv2];
}
- (void)layoutDiv0 {
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div0.mas_left).offset(kYYHeaderViewMarginLeft);
        make.centerY.equalTo(self.div0.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(100, 25));
    }];
}

- (void)layoutDiv1 {
    CGFloat kM5 = 5;
    [self.addressIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div1.mas_left).offset(kYYHeaderViewMarginLeft);
        make.size.mas_equalTo(CGSizeMake(15, 20));
        make.centerY.equalTo(self.div1.mas_centerY);
    }];
    [self.shopNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.addressIv.mas_right).offset(kM5);
        make.top.equalTo(self.div1.mas_top).offset(kM5);
        make.right.equalTo(self.div1.mas_right).offset(-10);
        make.height.mas_equalTo(23);
    }];
    [self.addressLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.shopNameLb.mas_left);
        make.top.equalTo(self.shopNameLb.mas_bottom).offset(5);
        make.right.equalTo(self.div1.mas_right).offset(-10);
        make.bottom.equalTo(self.div1.mas_bottom);
    }];
}

- (void)layoutDiv2 {
    [self.timeIv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.div2.mas_left).offset(kYYHeaderViewMarginLeft);
        make.centerY.equalTo(self.div2.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    [self.eatTimeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeIv.mas_right).offset(5);
        make.right.equalTo(self.div2.mas_right).offset(-10);
        make.centerY.equalTo(self.div2.mas_centerY);
        make.height.mas_equalTo(22);
    }];
}


#pragma mark - 二 getter
//!!!!:1、div0
- (UIView *)div0 {
    if (!_div0) {
        _div0 = [UIView new];
        _div0.backgroundColor = [UIColor whiteColor];
    }
    return _div0;
}
- (UILabel *)titleLb {
    if (!_titleLb) {
        _titleLb = [UILabel new];
        _titleLb.text = NSLocalizedString(Order_ReverseShop, @"预约门店");
    }
    return _titleLb;
}


//!!!!:1、div1
- (UIView *)div1 {
    if (!_div1) {
        _div1 = [UIView new];
        _div1.backgroundColor = [UIColor whiteColor];
    }
    return _div1;
}
- (UIImageView *)addressIv {
    if (!_addressIv) {
        _addressIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"address"]];
    }
    return _addressIv;
}
- (UILabel *)shopNameLb {
    if (!_shopNameLb) {
        _shopNameLb = [UILabel new];
        _shopNameLb.text = @"打铁关店";
    }
    return _shopNameLb;
}
- (UILabel *)addressLb {
    if (!_addressLb) {
        _addressLb = [UILabel new];
        _addressLb.text = @"杭州东激发了的纠纷杭州东激发了的纠纷杭州东激发了的纠纷杭州东激发了的纠纷a";
        _addressLb.textColor = [UIColor lightGrayColor];
//        _addressLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _addressLb;
}


//!!!!:1、div2
- (UIView *)div2 {
    if (!_div2) {
        _div2 = [UIView new];
        _div2.backgroundColor = [UIColor whiteColor];
    }
    return _div2;
}
- (UIImageView *)timeIv {
    if (!_timeIv) {
        _timeIv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"time"]];
    }
    return _timeIv;
}
- (UILabel *)eatTimeLb {
    if (!_eatTimeLb) {
        _eatTimeLb = [UILabel new];
        _eatTimeLb.text = @"用餐时间: 2018-11-12 16:30";
    }
    return _eatTimeLb;
}

#pragma mark - 一


/**更新表头数据*/
- (void)updateHeaderViewWithModel:(YuYueOrderDetailModel *)model
{
    self.shopNameLb.text = [NSString stringWithFormat:@"%@%@",model.shopName,model.address];
    
    self.addressLb.text = [NSString stringWithFormat:@"%@%@%@",model.name,model.sex,model.phone];
    
    self.eatTimeLb.text = [NSString stringWithFormat:@"用餐时间: %@",model.eatTime];
}

@end
